package com.wn.consumer.consumer2;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author yellow Docter
 * @date 2022 -08-31
 * @desc
 */
@Component
@Slf4j
public class MemberConsumer {

    /**
     *  @RabbitListener 监听队列的注解
     *
     *  创建交换机
     *  创建队列
     *  把交换机和队列进行绑定 ,消费者去队列中获取信息
     *
     *  创建一个队列:
     *     @Queue(name = "queue-fanout-member"),  name给队列名称
     *
     *    创建交换机:
     *    exchange = @Exchange(
     *          name = "exchange-fanout",
     *          type = ExchangeTypes.FANOUT
     *     )1
     *    @Exchange 创建交换机
     *       name 交换机的 名称
     *       type 交换机的 类型  ExchangeTypes.FANOUT(可以进行广播操作 )
     *
     *   @QueueBinding 把交换机和队列进行绑定
     * @param msg
     */
    @RabbitListener(
        bindings = @QueueBinding(
                value =@Queue(name = "queue-fanout-member"),
                exchange = @Exchange(
                        name = "exchange-fanout",
                        type = ExchangeTypes.FANOUT
                )
        )
    )
    public void consumerMember(String msg){
        log.info("会员消费者消费消息:{}",msg);
    }

}
